
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/28/2012 17:14:41
-- Generated from EDMX file: C:\Users\Radu\Documents\Visual Studio 11\Projects\Retete\Retete\Models\Retete.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Retete];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ReceptiiProduse_Receptii]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReceptiiProduse] DROP CONSTRAINT [FK_ReceptiiProduse_Receptii];
GO
IF OBJECT_ID(N'[dbo].[FK_ReteteProduse_Retete]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReteteProduse] DROP CONSTRAINT [FK_ReteteProduse_Retete];
GO
IF OBJECT_ID(N'[dbo].[FK_MeniuriRetete_Meniuri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MeniuriRetete] DROP CONSTRAINT [FK_MeniuriRetete_Meniuri];
GO
IF OBJECT_ID(N'[dbo].[FK_MeniuriRetete_Retete]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MeniuriRetete] DROP CONSTRAINT [FK_MeniuriRetete_Retete];
GO
IF OBJECT_ID(N'[dbo].[FK_VanzariElemente_Meniuri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ElementeVanzari] DROP CONSTRAINT [FK_VanzariElemente_Meniuri];
GO
IF OBJECT_ID(N'[dbo].[FK_VanzariElemente_Retete]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ElementeVanzari] DROP CONSTRAINT [FK_VanzariElemente_Retete];
GO
IF OBJECT_ID(N'[dbo].[FK_VanzariElemente_Vanzari]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ElementeVanzari] DROP CONSTRAINT [FK_VanzariElemente_Vanzari];
GO
IF OBJECT_ID(N'[dbo].[FK_ReteteProduse_Produse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReteteProduse] DROP CONSTRAINT [FK_ReteteProduse_Produse];
GO
IF OBJECT_ID(N'[dbo].[FK_ReceptiiProduse_Produse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ReceptiiProduse] DROP CONSTRAINT [FK_ReceptiiProduse_Produse];
GO
IF OBJECT_ID(N'[dbo].[FK_ElementeVanzari_Produse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ElementeVanzari] DROP CONSTRAINT [FK_ElementeVanzari_Produse];
GO
IF OBJECT_ID(N'[dbo].[FK_Stoc_Produse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Stoc] DROP CONSTRAINT [FK_Stoc_Produse];
GO
IF OBJECT_ID(N'[dbo].[FK_VanzariBonuri_Vanzari]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VanzariBonuri] DROP CONSTRAINT [FK_VanzariBonuri_Vanzari];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Receptii]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Receptii];
GO
IF OBJECT_ID(N'[dbo].[ReceptiiProduse]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReceptiiProduse];
GO
IF OBJECT_ID(N'[dbo].[Retete]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Retete];
GO
IF OBJECT_ID(N'[dbo].[ReteteProduse]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReteteProduse];
GO
IF OBJECT_ID(N'[dbo].[Meniuri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Meniuri];
GO
IF OBJECT_ID(N'[dbo].[MeniuriRetete]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MeniuriRetete];
GO
IF OBJECT_ID(N'[dbo].[Vanzari]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vanzari];
GO
IF OBJECT_ID(N'[dbo].[ElementeVanzari]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ElementeVanzari];
GO
IF OBJECT_ID(N'[dbo].[Produse]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Produse];
GO
IF OBJECT_ID(N'[dbo].[Stoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Stoc];
GO
IF OBJECT_ID(N'[dbo].[VanzariBonuri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VanzariBonuri];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Receptii'
CREATE TABLE [dbo].[Receptii] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Numar] int  NOT NULL,
    [Data] datetime  NOT NULL,
    [Tva] decimal(19,4)  NOT NULL,
    [FurnizorNume] nvarchar(100)  NULL,
    [FurnizorCodFiscal] nvarchar(50)  NULL,
    [FurnizorCodRegistruComert] nvarchar(50)  NULL,
    [FurnizorAdresa] nvarchar(250)  NULL,
    [FurnizorJudet] nvarchar(50)  NULL,
    [FurnizorCont] nvarchar(50)  NULL,
    [FurnizorBanca] nvarchar(50)  NULL,
    [TipDocumentLivrare] nvarchar(20)  NULL,
    [NumarDocumentLivrare] nvarchar(30)  NULL,
    [CorectieValoare] decimal(19,4)  NOT NULL,
    [CorectieValoareTva] decimal(19,4)  NOT NULL,
    [CorectieValoareCuTva] decimal(19,4)  NOT NULL
);
GO

-- Creating table 'ReceptiiProduse'
CREATE TABLE [dbo].[ReceptiiProduse] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDReceptie] int  NOT NULL,
    [Cantitate] decimal(18,0)  NOT NULL,
    [IDProdus] int  NOT NULL,
    [PretCumparare] decimal(19,4)  NOT NULL,
    [PretVanzare] decimal(19,4)  NOT NULL,
    [Gramaj] decimal(19,4)  NOT NULL,
    [AdmiteTVA] bit  NOT NULL
);
GO

-- Creating table 'Retete'
CREATE TABLE [dbo].[Retete] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Nume] varchar(100)  NOT NULL,
    [Pret] decimal(19,4)  NOT NULL,
    [Cod] nvarchar(10)  NOT NULL,
    [MultiplicatorCantitati] int  NOT NULL,
    [Categorie] varchar(30)  NOT NULL,
    [Cantitate] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'ReteteProduse'
CREATE TABLE [dbo].[ReteteProduse] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDReteta] int  NOT NULL,
    [Cantitate] decimal(18,0)  NOT NULL,
    [IDProdus] int  NOT NULL
);
GO

-- Creating table 'Meniuri'
CREATE TABLE [dbo].[Meniuri] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Denumire] nvarchar(100)  NOT NULL,
    [Valabilitate] datetime  NULL,
    [Pret] decimal(19,4)  NOT NULL,
    [Cod] nvarchar(10)  NOT NULL
);
GO

-- Creating table 'MeniuriRetete'
CREATE TABLE [dbo].[MeniuriRetete] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDReteta] int  NOT NULL,
    [Portii] decimal(18,0)  NOT NULL,
    [IDMeniu] int  NOT NULL
);
GO

-- Creating table 'Vanzari'
CREATE TABLE [dbo].[Vanzari] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ClientNume] nvarchar(100)  NULL,
    [ClientCodFiscal] nvarchar(50)  NULL,
    [ClientCodRegistruComert] nvarchar(50)  NULL,
    [ClientAdresa] nvarchar(250)  NULL,
    [ClientJudet] nvarchar(50)  NULL,
    [ClientCont] nvarchar(50)  NULL,
    [ClientBanca] nvarchar(50)  NULL,
    [Data] datetime  NULL,
    [Tip] nvarchar(50)  NULL,
    [FacturaNumar] int  NULL,
    [FacturaSerie] nvarchar(10)  NULL
);
GO

-- Creating table 'ElementeVanzari'
CREATE TABLE [dbo].[ElementeVanzari] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDVanzare] int  NOT NULL,
    [IDMeniu] int  NULL,
    [IDReteta] int  NULL,
    [Portii] decimal(19,4)  NOT NULL,
    [Pret] decimal(19,4)  NOT NULL,
    [IDProdus] int  NULL
);
GO

-- Creating table 'Produse'
CREATE TABLE [dbo].[Produse] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Nume] nvarchar(100)  NOT NULL,
    [PretCumparare] decimal(19,4)  NOT NULL,
    [UnitateMasura] nvarchar(10)  NOT NULL,
    [Categorie] nvarchar(20)  NOT NULL,
    [Cod] nvarchar(10)  NOT NULL,
    [Pret] decimal(19,4)  NOT NULL
);
GO

-- Creating table 'Stoc'
CREATE TABLE [dbo].[Stoc] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDProdus] int  NOT NULL,
    [Data] datetime  NOT NULL,
    [Cantitate] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'VanzariBonuri'
CREATE TABLE [dbo].[VanzariBonuri] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDVanzare] int  NOT NULL,
    [ValoareBon] decimal(19,4)  NOT NULL,
    [NumarBonuri] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Receptii'
ALTER TABLE [dbo].[Receptii]
ADD CONSTRAINT [PK_Receptii]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ReceptiiProduse'
ALTER TABLE [dbo].[ReceptiiProduse]
ADD CONSTRAINT [PK_ReceptiiProduse]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Retete'
ALTER TABLE [dbo].[Retete]
ADD CONSTRAINT [PK_Retete]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ReteteProduse'
ALTER TABLE [dbo].[ReteteProduse]
ADD CONSTRAINT [PK_ReteteProduse]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Meniuri'
ALTER TABLE [dbo].[Meniuri]
ADD CONSTRAINT [PK_Meniuri]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MeniuriRetete'
ALTER TABLE [dbo].[MeniuriRetete]
ADD CONSTRAINT [PK_MeniuriRetete]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Vanzari'
ALTER TABLE [dbo].[Vanzari]
ADD CONSTRAINT [PK_Vanzari]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ElementeVanzari'
ALTER TABLE [dbo].[ElementeVanzari]
ADD CONSTRAINT [PK_ElementeVanzari]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Produse'
ALTER TABLE [dbo].[Produse]
ADD CONSTRAINT [PK_Produse]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Stoc'
ALTER TABLE [dbo].[Stoc]
ADD CONSTRAINT [PK_Stoc]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'VanzariBonuri'
ALTER TABLE [dbo].[VanzariBonuri]
ADD CONSTRAINT [PK_VanzariBonuri]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [IDReceptie] in table 'ReceptiiProduse'
ALTER TABLE [dbo].[ReceptiiProduse]
ADD CONSTRAINT [FK_ReceptiiProduse_Receptii]
    FOREIGN KEY ([IDReceptie])
    REFERENCES [dbo].[Receptii]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReceptiiProduse_Receptii'
CREATE INDEX [IX_FK_ReceptiiProduse_Receptii]
ON [dbo].[ReceptiiProduse]
    ([IDReceptie]);
GO

-- Creating foreign key on [IDReteta] in table 'ReteteProduse'
ALTER TABLE [dbo].[ReteteProduse]
ADD CONSTRAINT [FK_ReteteProduse_Retete]
    FOREIGN KEY ([IDReteta])
    REFERENCES [dbo].[Retete]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReteteProduse_Retete'
CREATE INDEX [IX_FK_ReteteProduse_Retete]
ON [dbo].[ReteteProduse]
    ([IDReteta]);
GO

-- Creating foreign key on [IDMeniu] in table 'MeniuriRetete'
ALTER TABLE [dbo].[MeniuriRetete]
ADD CONSTRAINT [FK_MeniuriRetete_Meniuri]
    FOREIGN KEY ([IDMeniu])
    REFERENCES [dbo].[Meniuri]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeniuriRetete_Meniuri'
CREATE INDEX [IX_FK_MeniuriRetete_Meniuri]
ON [dbo].[MeniuriRetete]
    ([IDMeniu]);
GO

-- Creating foreign key on [IDReteta] in table 'MeniuriRetete'
ALTER TABLE [dbo].[MeniuriRetete]
ADD CONSTRAINT [FK_MeniuriRetete_Retete]
    FOREIGN KEY ([IDReteta])
    REFERENCES [dbo].[Retete]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeniuriRetete_Retete'
CREATE INDEX [IX_FK_MeniuriRetete_Retete]
ON [dbo].[MeniuriRetete]
    ([IDReteta]);
GO

-- Creating foreign key on [IDMeniu] in table 'ElementeVanzari'
ALTER TABLE [dbo].[ElementeVanzari]
ADD CONSTRAINT [FK_VanzariElemente_Meniuri]
    FOREIGN KEY ([IDMeniu])
    REFERENCES [dbo].[Meniuri]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VanzariElemente_Meniuri'
CREATE INDEX [IX_FK_VanzariElemente_Meniuri]
ON [dbo].[ElementeVanzari]
    ([IDMeniu]);
GO

-- Creating foreign key on [IDReteta] in table 'ElementeVanzari'
ALTER TABLE [dbo].[ElementeVanzari]
ADD CONSTRAINT [FK_VanzariElemente_Retete]
    FOREIGN KEY ([IDReteta])
    REFERENCES [dbo].[Retete]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VanzariElemente_Retete'
CREATE INDEX [IX_FK_VanzariElemente_Retete]
ON [dbo].[ElementeVanzari]
    ([IDReteta]);
GO

-- Creating foreign key on [IDVanzare] in table 'ElementeVanzari'
ALTER TABLE [dbo].[ElementeVanzari]
ADD CONSTRAINT [FK_VanzariElemente_Vanzari]
    FOREIGN KEY ([IDVanzare])
    REFERENCES [dbo].[Vanzari]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VanzariElemente_Vanzari'
CREATE INDEX [IX_FK_VanzariElemente_Vanzari]
ON [dbo].[ElementeVanzari]
    ([IDVanzare]);
GO

-- Creating foreign key on [IDProdus] in table 'ReteteProduse'
ALTER TABLE [dbo].[ReteteProduse]
ADD CONSTRAINT [FK_ReteteProduse_Produse]
    FOREIGN KEY ([IDProdus])
    REFERENCES [dbo].[Produse]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReteteProduse_Produse'
CREATE INDEX [IX_FK_ReteteProduse_Produse]
ON [dbo].[ReteteProduse]
    ([IDProdus]);
GO

-- Creating foreign key on [IDProdus] in table 'ReceptiiProduse'
ALTER TABLE [dbo].[ReceptiiProduse]
ADD CONSTRAINT [FK_ReceptiiProduse_Produse]
    FOREIGN KEY ([IDProdus])
    REFERENCES [dbo].[Produse]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReceptiiProduse_Produse'
CREATE INDEX [IX_FK_ReceptiiProduse_Produse]
ON [dbo].[ReceptiiProduse]
    ([IDProdus]);
GO

-- Creating foreign key on [IDProdus] in table 'ElementeVanzari'
ALTER TABLE [dbo].[ElementeVanzari]
ADD CONSTRAINT [FK_ElementeVanzari_Produse]
    FOREIGN KEY ([IDProdus])
    REFERENCES [dbo].[Produse]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ElementeVanzari_Produse'
CREATE INDEX [IX_FK_ElementeVanzari_Produse]
ON [dbo].[ElementeVanzari]
    ([IDProdus]);
GO

-- Creating foreign key on [IDProdus] in table 'Stoc'
ALTER TABLE [dbo].[Stoc]
ADD CONSTRAINT [FK_Stoc_Produse]
    FOREIGN KEY ([IDProdus])
    REFERENCES [dbo].[Produse]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Stoc_Produse'
CREATE INDEX [IX_FK_Stoc_Produse]
ON [dbo].[Stoc]
    ([IDProdus]);
GO

-- Creating foreign key on [IDVanzare] in table 'VanzariBonuri'
ALTER TABLE [dbo].[VanzariBonuri]
ADD CONSTRAINT [FK_VanzariBonuri_Vanzari]
    FOREIGN KEY ([IDVanzare])
    REFERENCES [dbo].[Vanzari]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VanzariBonuri_Vanzari'
CREATE INDEX [IX_FK_VanzariBonuri_Vanzari]
ON [dbo].[VanzariBonuri]
    ([IDVanzare]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------